package com.lj.eduservice.service.impl;

import com.lj.eduservice.client.VodClient;
import com.lj.eduservice.entity.Video;
import com.lj.eduservice.mapper.VideoMapper;
import com.lj.eduservice.service.VideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lj.utils.exception.APIException;
import com.lj.utils.result.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author luojing
 * @since 2021-05-06
 */
@Service
public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements VideoService {

    @Autowired
    private VodClient vodClient;

    @Override
    @Transactional
    public Boolean deleteVideo(Video video) {
        //先删小节的视频
        if (video.getVideoSourceId() != null && !"".equals(video.getVideoSourceId())) {
            ResultVO<Boolean> delete = vodClient.delete(video.getVideoSourceId());
            if (delete.getData() == false) {
                throw new APIException(delete.getCode(), delete.getMsg());
            }
        }
        //再删除小节信息
        this.removeById(video.getId());
        return true;
    }
}
